package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.provinceindex.LindiProvinceIndexQueryVO;
import com.minimalist.common.entity.lindi.vo.provinceindex.LindiProvinceIndexVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiProvinceIndexService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_省级指标管理")
@RequestMapping("/lindi/provinceIndex")
public class LindiProvinceIndexController{

    @Autowired
    private LindiProvinceIndexService service;

    @PostMapping("/addProvinceIndex")
    @Operation(summary = "添加省级指标")
    public R<?> addProvinceIndex(@RequestBody @Validated(Add.class) LindiProvinceIndexVO indexVO){
        service.addProvinceIndex(indexVO);
        return R.ok();
    }

    @DeleteMapping("/deleteProvinceIndexByProvinceIndexId")
    @Operation(summary = "删除省级指标 -> 根据省级指标ID删除")
    public R<?> deleteProvinceIndexByProvinceIndexId(
            @RequestParam("provinceIndexId")
            @NotNull(message = "省级指标ID不能为空")
            @Parameter(name = "provinceIndexId", required = true, description = "省级指标ID")
            Long provinceIndexId){
        service.deleteProvinceIndexByProvinceIndexId(provinceIndexId);
        return R.ok();
    }

    @PutMapping("/updateProvinceIndexByProvinceIndexId")
    @Operation(summary = "修改省级指标")
    public R<?> updateProvinceIndexByProvinceIndexId(@RequestBody @Validated(Update.class) LindiProvinceIndexVO indexVO){
        service.updateProvinceIndexByProvinceIndexId(indexVO);
        return R.ok();
    }

    @GetMapping("/getPageProvinceIndexList")
    @Operation(summary = "查询省级指标列表(分页)")
    public R<PageResp<LindiProvinceIndexVO>> getPageProvinceIndexList(LindiProvinceIndexQueryVO queryVO){
        return R.ok(service.getPageProvinceIndexList(queryVO));
    }

    @GetMapping("/getProvinceIndexByProvinceIndexId/{provinceIndexId}")
    @Operation(summary = "根据省级指标ID查询省级指标")
    public R<LindiProvinceIndexVO> getProvinceIndexByProvinceIndexId(
            @PathVariable(value = "provinceIndexId")
            @NotNull(message = "省级指标ID不能为空")
            @Parameter(name = "provinceIndexId", description = "省级指标ID", required = true)
            Long provinceIndexId){
        return R.ok(service.getProvinceIndexByProvinceIndexId(provinceIndexId));
    }
}